package com.atguigu.gmall.file;


import com.atguigu.gmall.product.ServiceProductApplication;
import org.csource.fastdfs.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.util.ClassUtils;


@RunWith(SpringRunner.class)
@SpringBootTest(classes = ServiceProductApplication.class)
public class FileDemo {

    @Test
    public void testFile() throws Exception{


        String path = ClassUtils.getDefaultClassLoader().
                getResource("fast_client.conf").getPath();
        //底层 IO 磁盘  绝对路径
        ClientGlobal.init(path);

        //读取resource/fast_client.conf
        //连接的上跟踪器
        TrackerClient trackerClient = new TrackerClient();

        //连接
        TrackerServer trackerServer = trackerClient.getConnection();
        //扩展
        StorageServer storageServer = null;
        //连接Storage
        StorageClient1 storageClient1 = new StorageClient1(trackerServer,storageServer);
        //上传文件
        String fileId = storageClient1.upload_file1(
                "D:\\尚品汇商城\\资料\\图片\\logo\\0bedaba1e05119ac.jpg",
                "jpg", null);
        System.out.println("http://192.168.200.128:8080/" + fileId);

    }


}
